package daily.may0514;

public class VariableArgsTest {
    public static void main(String[] args) {
        int sum = add(1,2,3,4,5);
        System.out.println(sum);//15
    }

    //计算未知个整数的和
    public static int add(int... args) {
        System.out.println(args);//[I@10f87f48，可见args底层是个数组
        System.out.println(args.length);//5
        int sum = 0;
        for (int i : args) {
            sum += i;
        }
        return sum;
    }
}
